package com.example.thornchg.yc_plane_game;

import android.view.MotionEvent;

import org.cocos2d.extensions.scroll.CCScrollView;
import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.transitions.CCFlipXTransition;
import org.cocos2d.transitions.CCJumpZoomTransition;
import org.cocos2d.types.CGSize;

import java.util.ArrayList;

public class RankLayer extends CCLayer {
    private CGSize winSize;

    public RankLayer() {
        winSize = CCDirector.sharedDirector().winSize();
        CombatMap combatMap=new CombatMap(this);

        CCLabel ccLabel1=CCLabel.makeLabel("排行榜","Arial",80);
        ccLabel1.setPosition(ccp(winSize.getWidth()/2,winSize.getHeight()/8*7));
        addChild(ccLabel1);
        MyDatabaseHelper myDatabaseHelper=new MyDatabaseHelper(CCDirector.theApp,"planeGame.db",
                null,1);
        DBHandle dbHandle=new DBHandle();
        ArrayList<String> historyScoreList = dbHandle.getHistoryScoreList(myDatabaseHelper.getReadableDatabase());
        for (int i = 0; i < historyScoreList.size(); i++) {
            CCLabel ccLabel=CCLabel.makeLabel(i+1+".",
                    "Arial",50);
            if (i==0)
                ccLabel.setColor(ccc3(216,255,0));
            else if (i<3)
                ccLabel.setColor(ccc3(255,0,0));
            ccLabel.setPosition(ccp(winSize.getWidth()/2-150, winSize.getHeight()/6*4-i*50));
            addChild(ccLabel);
            CCLabel ccLabel_score=CCLabel.makeLabel(historyScoreList.get(i),
                    "Arial",50);
            ccLabel_score.setPosition(ccp(winSize.getWidth()/2+50, winSize.getHeight()/6*4-i*50));
            addChild(ccLabel_score);
        }
        setIsTouchEnabled(true);
    }

    @Override
    public boolean ccTouchesBegan(MotionEvent event) {
        CCScene ccScene=CCScene.node();
        ccScene.addChild(new StartReadyLayer());
        CCFlipXTransition ccFlipXTransition=CCFlipXTransition.transition(1f,ccScene,1);
        CCDirector.sharedDirector().runWithScene(ccFlipXTransition);
        return super.ccTouchesBegan(event);
    }
}
